<?php
	require_once('start_session.php');
	$_SESSION['ip'] = '';
	$_SESSION['location'] = '';
	$_SESSION['connect_time'] = '';
	$_SESSION['latitude'] = '';
	$_SESSION['longitude'] = '';
	session_destroy();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>~설문설문~</title>
<link href="./css/form.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="css/dark.datetimepicker.css" />
<script type="text/javascript" src="./js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="./js/ui.datetimepicker.js"></script>
<script type="text/javascript" src="./js/util.js"></script>
<script type="text/javascript">
	var conn_time = null;
	$('document').ready(function() {
		$('#gps_div').hide();
		$.getJSON("get_location.php", function(data) {
			$.each(data.ap, function(ap, ap_info) {
				$('#location').append("<option value='" + ap_info.location + "'>" + ap_info.location + "</option>");
			});
		});
		
		var locationType = $('#location_type');
		locationType.change(function() {
			// $.getJSON("get_location.php", function(data) {
				// $('#location').empty();
				// if (locationType.val() == "indoor") {
					// $.each(data.ap, function(ap, ap_info) {
						// $('#location').append("<option value='" + ap_info.location + "'>" + ap_info.location + "</option>");
					// });
				// }
				// else {
					// $.each(data.gps, function(gps, gps_info) {
						// $('#location').append("<option value='" + gps_info.location + "'>" + gps_info.location + "</option>");
					// });
				// }
			// });
			if (locationType.val() == "indoor") {
				$('#ap_div').show();
				$('#gps_div').hide();
			}
			else {
				$('#ap_div').hide();
				$('#gps_div').show();
			}
		});
		
		conn_time = $('#connect_time');
		conn_time.datetimepicker({dateFormat: 'yy-mm-dd', dayNamesMin: ['일', '월', '화', '수', '목', '금', '토']});	
		
		$('#select_gps').click(function(evt) {
			openPopup("select_gps_location.php", "select_gps_loc", 800, 650);
		});
	});

	function processForm() {
		// if (document.getElementById("connect_time").value == "") {
			// alert('접속시간을 입력해주세요');
			// return false;
		// }
		var curTime = new Date();
		$('#connect_time').val(printNow());
		$('#connect_gate').submit();
	}
</script>
<style>
<!--
#gps_div label[for="latitude"], #gps_div label[for="longitude"] {
	font: 12px "Trebuchet MS", Arial, Helvetica, sans-serif;
	text-align: left;
}
-->
</style>
</head>
<body>
	<form id="connect_gate" method="post" action="connect_gate.php">
		<h1>~설문설문~에 오셨습니다</h1>
		<fieldset>
			<legend>테스트 설정</legend>
			<div>
				<label for="location" class="label">접속장소: </label>
				<select id="location_type" name="location_type">
					<option value="indoor">실내</option>
					<option value="outdoor">실외</option>
				</select>
				<span id="ap_div">
					<select id="location" name="location">
					</select>
				</span>
				<span id="gps_div" style="">
					<label for="latitude">위도</label><input type="text" id="latitude" name="latitude" size="15" readonly="true" class="readonly" />
					<label for="longitude">경도</label><input type="text" id="longitude" name="longitude" size="15" readonly="true" class="readonly" />
					<input id="select_gps" type="button" value="선택" />
				</span>
			</div>
			<div>
				<label for="ip" class="label">테스트 IP: </label>
				<select id="ip" name="ip">
				<?php
					require_once('db_connect.php');
					$query = "select * from test_ip";
					$data = mysqli_query($conn, $query)
						or die("test_ip 테이블 가져오기 실패");
					while ($row = mysqli_fetch_array($data)) {
						echo '<option value="'.$row['ip'].'">'.$row['ip'].'</option>';
					}
				?>			
				</select>
			</div>
<!--
			<div>
				<label for="location" class="label">접속시간: </label>
				<input type="text" name="connect_time" id="connect_time" size="26" />
			</div>
-->
		<input type="hidden" id="connect_time" name="connect_time" />
		</fieldset>
		<div class="submit">
			<input type="button" value="확인" onclick="processForm();">
		</div>
	</form>
</body>
</html>